<script type="text/javascript">
$(document).ready(function(){
	var users = [];
	$("#addFrom").hide();
	
	$("#add").on("click",function(){
		var name =  $("input[name='name']").val();
		var grade = $("input[name='grade']").val();
		var code = $("input[name='code']").val();
		var status = $('input:radio[name="status"]:checked').val();
		var introduction = $("textarea[name='introduction']").val();
		var userIds = "";
		$.each(users, function (index) {
			userIds = userIds + users[index] + ',';
		});
		$.post("${path}/group/addGroup",{
			name:name,
			grade:grade,
			status:status,
			code:code,
			introduction:introduction,
			userIds:userIds
			}
		,function(data){
			if(data.success){
				window.location.href="${path}/group/list";
			}
		});
	});
	$("#addHtml").on("click",function(){
		$("#addFrom").show();
	});
	$("#cancelBtu").on("click",function(){
		$("#addFrom").hide();
	})
	$("#saveBut").on("click",function(){
		$("#myTable").html("");
		var user = "";
		var checkbox=$("input[name='check']");
	    for(i=0;i<checkbox.length;i++){
	        if(checkbox[i].checked){
	        	user = user + checkbox[i].value + ",";
	        }
	    }
	    if(user != ""){
	    	$.post("${path}/group/queryUser",{userIds:user},function(data){
	    		if(data.success){
	    			users = [];
	    			$.each(data.message, function (index) {
	    			  users.push(data.message[index].ID);
    		          var rowTr = document.createElement('tr')
    		          //找到html的tr节点
    	              var child = "<td>" + data.message[index].userName +  "</td>"
    	              + "<td>" + data.message[index].company+  "</td>"
    	              + "<td>" + data.message[index].major+  "</td>"
    	               //将要展示的信息写入页面
    	               rowTr.innerHTML = child;
    	               $("#myTable").append(rowTr);//将信息追加
    		   		});
    		    	$("#addFrom").hide();
	    		}
	    	});
	    }
	});
});
</script>
<div>
	组名称：<input name= "name"><br/>
	组等级：<input name= "grade"><br/>
	组代码：<input name= "code"><br/>
	组状态：<input id="z1" type="radio" value="0" name="status" checked/>正常启用
		   <input id="z2" type="radio" value="1" name="status"/>异常  <br/>
	描述：<textarea name="introduction"></textarea><br/>
	成员：<button id="addHtml">添加成员</button>
	<table id="myTable">
	</table>
	<button id="add">保存</button>
</div>
<div id="addFrom">
	<form action="">
		<input name="condition">
		<button>查询</button>
	</form>
	<div>
		#foreach ($item in $list)
			<input type="checkbox" name="check" value="${item.id}" />
				$!{velocityCount}: ${item.userName}-
				#if($item.sex == 0)<span>男</span>#end #if($item.sex == 1)<span>女</span>#end-
				${item.company}-
				#if($item.major)<span>${item.major}</span> #else <span>没有专业</span> #end <br/>
		#end
	</div>
	<button id="saveBut">保存</button><button id="cancelBtu">取消</button>
</div>